package com.wanmait.employment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.employment.entity.RecruitmentEducation;
import com.wanmait.employment.entity.WelfareLabelBasics;
import com.wanmait.employment.mapper.WelfareLabelBasicsMapper;
import com.wanmait.employment.service.WelfareLabelBasicsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class WelfareLabelBasicsServiceImpl extends ServiceImpl<WelfareLabelBasicsMapper,WelfareLabelBasics> implements WelfareLabelBasicsService {

    @Resource
    private WelfareLabelBasicsMapper welfareLabelBasicsMapper;
    @Override
    public PageInfo<WelfareLabelBasics> selectList(String title, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<WelfareLabelBasics> queryWrapper=new QueryWrapper<>();
        queryWrapper.like("title",title);
        List<WelfareLabelBasics> welfareLabelBasics=welfareLabelBasicsMapper.selectList(queryWrapper);
        PageInfo<WelfareLabelBasics> welfareLabelBasicsPageInfo=new PageInfo<>(welfareLabelBasics);
        return welfareLabelBasicsPageInfo;
    }

    @Override
    public void update(WelfareLabelBasics welfareLabelBasics) {

        welfareLabelBasicsMapper.updateById(welfareLabelBasics);
    }

    @Override
    public Boolean insert(WelfareLabelBasics welfareLabelBasics) {
        LambdaQueryWrapper<WelfareLabelBasics> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(WelfareLabelBasics::getTitle,welfareLabelBasics.getTitle());
        WelfareLabelBasics welfareLabelBasics1=welfareLabelBasicsMapper.selectOne(wrapper);
        System.out.println(welfareLabelBasics1);
        if(welfareLabelBasics1==null){
            welfareLabelBasicsMapper.insert(welfareLabelBasics);
            return true;
        }else{
            return false;
        }

    }

    @Override
    public void delete(Integer id) {
        welfareLabelBasicsMapper.deleteById(id);
    }
}
